<template>
  <el-dialog :title="title" :width="width" :visible.sync="isShowVisible" center :close-on-click-modal="false" :before-close="() => $emit('close')">
    <el-card>
      <el-form label-width="105px" :model="groupData" ref="groupData" :rules="rules" v-loading="isLoading">

        <el-row>
            <el-col :span="8">
            <el-form-item label="设备编码:" prop="fnumber" id="fnumber" required>
              <el-input  v-model="groupData.fnumber"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备名称:" prop="fname" required>
              <el-input v-model="groupData.fname"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备简称:" prop="fsimplename" >
              <el-input v-model="groupData.fsimplename"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="型号:" prop="fmodel" >
              <el-input v-model="groupData.fmodel"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="功率:" prop="fpower">
              <el-input v-model="groupData.fpower"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备分类:" prop="fgroupid">
              <el-select v-model="groupData.fgroupid" >
                <el-option v-for="item in groupList" :key="item.nodeId" :label="item.nodeName" :value="item.nodeId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="出厂编号:" prop="foutnumber" >
              <el-input v-model="groupData.foutnumber"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出厂日期:" prop="foutdate" >
              <el-date-picker v-model="groupData.foutdate" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="购入日期:" prop="fbuydate" >
              <el-date-picker v-model="groupData.fbuydate" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="使用地点:" prop="fuseaddress" >
              <el-input v-model="groupData.fuseaddress"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产厂家:" prop="fmanufacturer" >
              <el-input v-model="groupData.fmanufacturer"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="验收日期:" prop="fcheckindate" >
              <el-date-picker v-model="groupData.fcheckindate" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="采集数据:" prop="fiscollectdata"  required>
                <el-radio-group v-model="groupData.fiscollectdata">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="关键设备:" prop="fiskey"  required>
              <el-radio-group v-model="groupData.fiskey">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="主设备:" prop="fismain"  required>
              <el-radio-group v-model="groupData.fismain">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="技术水平:" prop="flevel" >
              <el-select v-model="groupData.flevel">
                <el-option v-for="item in returnTypeList" :key="item.code" :label="item.name" :value="item.code">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="运行状态:" prop="frunstate" >
              <el-select v-model="groupData.frunstate"placeholder="请选择" >
                <el-option v-for="item in returnResultList" :key="item.code" :label="item.name" :value="item.code">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="关联主设备:">
              <el-select v-model="groupData.fmainequipmentid" > <!--disabled class="select-disabled"-->
               <!-- <el-select v-model="groupData.fmainequipmentid" label="1">是</el-select>
                <el-select v-model="groupData.fmainequipmentid" label="0">否</el-select>-->
              <!-- <demo-facility ref="search_facility" v-model="groupData.fmainequipmentid"></demo-facility>-->
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>



        <el-row>
          <el-col :span="8">
            <el-form-item label="吨位:"><!--@change="handleChange"-->
              <el-input-number v-model="groupData.ftonnage"  :min="1" :max="10" label="描述文字"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车间:"><!--:disabled="groupId != 0" disabled class="select-disabled" -->
              <!--<el-input v-model="groupData.fcreatorid"></el-input>-->
               <el-select v-model="groupData.ffactopryid">
                 <el-option v-for="item in queryFactoryList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
                 </el-option>
               </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="顺序:">
              <el-input-number v-model="groupData.forderno"  :min="1" :max="20" label="描述文字"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注:">
              <el-input v-model="groupData.fremark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveGroup">保存</el-button>
      <el-button @click="$emit('notRefresh')">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
    import EquipmentGroupApi from "../../../api/module/EquipmentGroupApi";

    export default {
      name: "facility_addEdit",
      props: {
        width: {type: String, default: '60vw'},
        fid:Number,
      },
      data () {
        /*const validateParentId = (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请选择上级分类'))
          } else {
            callback()
          }
        };*/
        return {
          title: '新增设备',
          isShowVisible: true,

          rules: {
            fnumber: [{ required: true, message: '请填写设备编码', tirgger: 'blur' }],
            fname: [{ required: true, message: '请填写设备名称', tirgger: 'blur' }],
          },
          groupData: {},
          groupList: [],
          returnTypeList:[],
          returnResultList:[],
          queryFactoryList:[],
          //FisMainList:[],
          isLoading: false,
          funmber:'',
          http:new EquipmentGroupApi(),
        }
      },
      async created () {
        this.isLoading = true
        let groupList = await this.http.queryGroupTree({})
        let queryFactoryList = await this.http.queryFactoryList({})
        this.queryFactoryList = queryFactoryList.data;
        console.log("车间")
        console.log(queryFactoryList.data)
        //let FisMainList = await this.http.getFisMain({})
        let returnTypeList = await this.http.getEnum({sysName:"tie-demo",className:"cn.hxlc.tie.demo.core.enums.LevelEnum"});
        this.returnTypeList = returnTypeList.data;
        let returnResultList = await this.http.getEnum({sysName:"tie-demo",className:"cn.hxlc.tie.demo.core.enums.DeptEnum"})
        this.returnResultList = returnResultList.data;
        console.log(returnResultList)

        this.groupList = groupList.data
        console.log("fid:"+this.fid)
        if (!this.fid) {
          console.log("fid:##"+this.fid)
          console.log("新增")
          let groupData = {}
          groupData.eparentid = this.eparentid + ""
          this.groupData = groupData
        } else {
            this.title = '编辑设备'
            console.log("编辑设备:"+this.fid)
            let groupData = await this.http.detail({fid: this.fid})
            this.groupData = groupData.data
            console.log(groupData)
        }
        this.isLoading = false
      },
      methods:{
        saveGroup(){
              if (this.fid) {
                this.http.updateFacility(this.groupData).then(res => {
                  this.$tie.showSuccess(res.message)
                  this.$emit('close')
                }).catch(e => {
                  loading.close()
                })
              } else {
                this.http.addFacility(this.groupData).then(res => {
                  loading.close()
                  this.$tie.showSuccess(res.message)
                  this.$emit('close')
                }).catch(e => {
                  loading.close()
                })
              }
            }
         /* })
        }*/
      }
    }
</script>

<style scoped>

</style>
